﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Componnent.Common;
using WaterRevenueMS.Domain.ViewModels.BasicSet.WaterCaliber;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IWaterCaliberService))]
    public class WaterCaliberService : CoreServiceBase, IWaterCaliberService
    {
        [Import]
        public IWaterCaliberRepository WaterCaliberRepository { get; set; }

        public IQueryable<WaterCaliber> WaterCalibers
        {
            get { return WaterCaliberRepository.Entities; }
        }

        public OperationResult Insert(WaterCaliberModel model)
        {
            var entity = new WaterCaliber
            {
                Shui_BKJ=model.Shui_BKJ,
                DefaultValue=model.DefaultValue,
                CreateDT=DateTime.Now,
                ReviseDT=DateTime.Now,
                OrderNo=model.OrderNo,
                Fan_BZDZ=model.Fan_BZDZ,
                Bao_JZDZ=model.Bao_JZDZ,
                Bao_XFY=model.Bao_XFY,
                Chai_BFY=model.Chai_BFY
            };
            WaterCaliberRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(WaterCaliberModel model)
        {
            var entity = WaterCaliberRepository.Entities.FirstOrDefault(t => t.Id == model.Id);
            if (entity != null)
            {
                entity.Shui_BKJ = model.Shui_BKJ;
                entity.DefaultValue = model.DefaultValue;
                entity.ReviseDT = DateTime.Now;
                entity.OrderNo = model.OrderNo;
                entity.Fan_BZDZ = model.Fan_BZDZ;
                entity.Bao_JZDZ = model.Bao_JZDZ;
                entity.Bao_XFY = model.Bao_XFY;
                entity.Chai_BFY = model.Chai_BFY;
                WaterCaliberRepository.Update(entity);
            }
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var entity = WaterCaliberRepository.Entities.FirstOrDefault(t => t.Id == Id);
            if (entity != null)
            {
                WaterCaliberRepository.Delete(entity);
            }
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
